package com.liaojp.sccp.controller;

import com.liaojp.sccp.Param.user.Login;
import com.liaojp.sccp.Param.user.Register;
import com.liaojp.sccp.common.Result;
import com.liaojp.sccp.service.UsersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/users")
public class UserController {
    private final UsersService usersService;

    public UserController(UsersService usersService) {
        this.usersService = usersService;
    }

    /**
     * 登录
     * @param login 用户名 密码
     * @return Result
     */
    @PostMapping("/login")
    public Result login(@RequestBody Login login) {
        log.info("登录");
        String username = login.getUsername();
        String password = login.getPassword();

        return usersService.login(username, password);
    }

    /**
     * 注册
     * @return Result
     */
    @PostMapping("/register")
    public Result register(@RequestBody Register register) {
        log.info("注册");
        return usersService.register(register.getUsername(), register.getPassword());
    }
}
